home *** CD-ROM | disk | FTP | other *** search
File List | 1988-11-20 | 5.1 KB | 185 lines |
- Rem This program is from Astronomy Magazine December 1988
- Rem Article name: Galactic Collisions on Your Computer
- Rem Authors: Michael C. Schroeder & Neil Comins
- Rem GFA conversion version by James Kajpust
- Rem No program copyright listed, program offered free by magazine
- Rem
- Rem Units used:
- Rem G (universal gravitational constant = 1
- Rem t (time unit T.U.) = 1.2 million years
- Rem d (distance D.U.) = 500 Parsecs
- Rem = 1630 light years
- Rem m (mass unit M.U.) = 20 Billion solar masses
- Rem The TARGET galaxy is a disk and the INTRUDER galaxy is point.
- Rem
- Rem ----------------------------------------------------------------
- Rem
- Dim X(1000),Y(1000),Vx(1000),Vy(1000),Z(1000),Vz(1000)
- Cls
- Rem The main program
- Gosub Input_data
- Gosub Init_compute
- Gosub Particle_pusher
- Gosub Screen_display
- Print At(0,0);"Press [Control]+[Shift]+[Enter] to escape ";
- Procedure Init_compute
- Cls
- Print At(30,24);"Galaxies in Collision"
- Print At(16,22);"Polar View";
- Print At(54,22);"Edge View";
- Line 0,330,640,330
- Line 320,0,320,360
- Line 0,360,640,360
- Rem Initialize TARGET galaxy mass, position and velocity.
- M1=5
- X1=150
- Y1=100
- Vx1=0
- Vy1=0
- Z1=0
- Vz1=0
- Sf2=2
- Rem Scale INTRUDER galaxy mass, position and velocity.
- Time=0
- M2=M2*M1
- X2=X2+X1
- Y2=Y2+Y1
- Z2=Z2+Z1
- Rem Set up initial load
- Rem Place stars in concentric rings from R=10 to R=30 at intervals of dr.
- For Ir=1 To Nrr
- R=10+(Ir-1)*Dr
- V=Sqr(M1/R)
- Th=(0.5*V/R)*(180/Pi)
- If R=10 Then
- V=0.9*V
- Endif
- For It=1 To Nrs
- T=(It-1)*360/Nrs
- T1=Pi*(T-Th)/180
- I=I+1
- Rem Initialize star positions
- X(I)=R*Cos(T/57.2958)+150
- Y(I)=R*Sin(T/57.2958)+100
- Vz(I)=0
- Z(I)=0
- Rem Initialize star velocities to place them in circular orbits about
- Rem the TARGET galaxy
- Vx(I)=-V*Sin(T1)
- Vy(I)=V*Cos(T1)
- Next It
- Next Ir
- Gosub Screen_display
- Return
- Procedure Particle_pusher
- For K=1 To Ntspr
- For J=1 To 1
- For I=1 To Ns
- Rem Determine the force on a star due to the galactic centers.
- Rem SF2 below, called the softening factor is used to prevent
- Rem overflows during force calculations. SF2 is assigned a value
- Rem above. Should be small as possible to better approximate
- Rem a true 1/r**2 force.
- R1=M1/((X(I)-X1)^2+(Y(I)-Y1)^2+(Z(I)-Z1)^2+2+Sf2)^1.5
- R2=M2/((X(I)-X2)^2+(Y(I)-Y2)^2+(Z(I)-Z2)^2+2+Sf2)^1.5
- Rem calculate stars x,y,z accelerations
- Ax=R1*(X1-X(I))+R2*(X2-X(I))
- Ay=R1*(Y1-Y(I))+R2*(Y2-Y(I))
- Az=R1*(Z1-Z(I))+R2*(Z2-Z(I))
- Rem Update star positions and velocities using a time centered
- Rem leap-frog algorithm
- Vx(I)=Vx(I)+Ax
- Vy(I)=Vy(I)+Ay
- Vz(I)=Vz(I)+Az
- X(I)=X(I)+Vx(I)
- Y(I)=Y(I)+Vy(I)
- Z(I)=Z(I)+Vz(I)
- Next I
- Rem Update positions and velocities of the galactic centers
- Rr=((X1-X2)^2+(Y1-Y2)^2+(Z1-Z2)^2+Sf2)^1.5
- Ax=(X2-X1)/Rr
- Ay=(Y2-Y1)/Rr
- Az=(Z2-Z1)/Rr
- Vx1=Vx1+M2*Ax
- Vy1=Vy1+M2*Ay
- Vz1=Vz1+M2*Az
- Vx2=Vx2-M1*Ax
- Vy2=Vy2-M1*Ay
- Vz2=Vz2-M1*Az
- X1=X1+Vx1
- Y1=Y1+Vy1
- Z1=Z1+Vz1
- X2=X2+Vx2
- Y2=Y2+Vy2
- Z2=Z2+Vz2
- Time=Time+1
- Next J
- Gosub Screen_display
- Next K
- Return
- Procedure Screen_display
- Rem Calculate center of mass of system for use of center of output display
- Xc=(M1*X1+M2*X2)/(M1+M2)
- Yc=(M1*Y1+M2*Y2)/(M1+M2)
- Zc=(M1*Z1+M2*Z2)/(M1+M2)
- Rem Calculate position of galactic centers and display on screen
- Xx1=(X1-Xc)
- Yy1=(Y1-Yc)
- Zz1=(Z1-Zc)
- Xx2=(X2-Xc)
- Yy2=(Y2-Yc)
- Zz2=(Z2-Zc)
- Circle Xx1+160,Yy1+160,4
- Circle Xx1+480,2*Zz1+160,4
- Circle Xx2+160,Yy2+160,4
- Circle Xx2+480,2*Zz2+160,4
- Rem put stars on screen
- For I=1 To Ns
- Xp=(X(I)-Xc)
- Yp=(Y(I)-Yc)
- Zp=2*(Z(I)-Zc)
- Plot Xp+160,Yp+160
- Plot Xp+480,Zp+160
- Next I
- Print At(24,25);"Time = ";
- Print Using "###.#",Time*1.2;
- Print " millions of years";
- Return
- Rem ------------------------------------------------------
- Procedure Input_data
- Input "Do you wish to use stored data (y/n)?";A$
- If A$="n" Or A$="N" Then
- Gosub Request_data
- Else
- Gosub Stored_data
- Endif
- Return
- Procedure Stored_data
- Nrr=8
- Nrs=10
- Ns=Nrr*Nrs
- Dr=40/(Nrr-1)
- M2=0.25
- X2=40
- Y2=10
- Z2=10
- Vx2=-1
- Vy2=0
- Vz2=0
- Ntspr=1200
- Return
- Procedure Request_data
- Input "Input the number of rings of stars in the TARGET galaxy ";Nrr
- Input "Input the number of stars per ring in the TARGET galaxy";Nrs
- Ns=Nrr*Nrs
- Dr=40/(Nrr-1)
- Print
- Input "Input mass fraction of INTRUDER galaxy in unit of the taget galaxy mass ";M24
- Print
- Input "Input the initial X, Y, and Z coordinates of the INTRUDER galaxy ";X2,Y2,Z2
- Print
- Input "Input the initial X, Y, and Z velocities of the INTRUDER galaxy ";Vx2,Vy2,Vz2
- Print
- Input "Input the number of time steps for this run ";Ntspr
- Return
-